#include<iostream>
#include<stdio.h>
#include<unistd.h>
using namespace std;
int val1;
int val2=1;
//内存不同位置的存储类型
void test1()
{

    printf("代码区：%p\n",test1);
    const char*str="hello linux";
    printf("字符常量区：%p\n",str);
    printf("已初始化全局变量区：%p\n",&val2);
    printf("未初始化全局变量区：%p\n",&val1);
    char*mem=new char;
    char*mem1=new char;
    char*mem2=new char;
    printf("堆区：%p\n",mem);
    printf("堆区：%p\n",mem1);
    printf("堆区：%p\n",mem2);
    printf("栈区：%p\n",&str);
    printf("栈区：%p\n",&mem);
    int a;
    int b;
    int c;
    printf("栈区：%p\n",&a);
    printf("栈区：%p\n",&b);
    printf("栈区：%p\n",&c);
}

//父子进程的关系
int val=100;
void test2()
{
    pid_t id=fork();
    int count=5;
    if(id==0)
    {
        while(1)
        {
        printf("I am child,pid:%d,ppid:%d,val:%d,&val:%p\n",getpid(),getppid(),val,&val);
        if(count) count--;
        else{
            cout<<"change val 100->200"<<endl;
            val=200;
            count--;
            }
        sleep(1);
        }
        
    }
    else{
        while(1)
        {
             printf("I am parent,pid:%d,ppid:%d,val:%d,&val:%p\n",getpid(),getppid(),val,&val);
            sleep(1);
        }

    }
}
int main()
{
    test1();
    test2();
    return 0;
}
